# This file is part of The Vu Toolkit.
#
# The Vu Toolkit is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# The Vu Toolkit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with The Vu Toolkit; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
#
# Copyright © Zak Fenton 2008
#

module Vu::SVG
	
	# Base class for a shape in SVG (path, rect, circle, etc.)
	class Shape < Node
		def initialize ()
			@fill = nil
			@stroke = nil
			@stroke_width = 1
		end
	
		# Returns true if the shape contains the given mouse co-ordinates,
		# including child shapes, or false otherwise.
		def contains? (x,y)
		end
		
		# Renders the shape onto a Cairo context.
		# Usually overriding trace_to_cairo for specific shapes should suffice
		# to customise rendering.
		def render_to_cairo (cr)
			if @fill
				trace_to_cairo(cr)
				@fill.apply_to_cairo(cr)
				cr.fill()
			end
			if @stroke
				trace_to_cairo(cr)
				@stroke.apply_to_cairo(cr)
				cr.line_width = stroke_width
				cr.stroke()
			end
		end
		
		# Only traces the path of the shape onto a Cairo context
		def trace_to_cairo (cr)
			raise "#{self.class}.trace_to_cairo not implemented!"
		end
		
		# Sets the paint used to fill this shape
		def fill= (p)
			@fill = p
		end
		
		# Sets the paint used to stroke the outline
		def stroke= (p)
			@stroke = p
		end
		
		# Sets the width of the stroke/outline
		def stroke_width= (w)
			@stroke_width = w
		end
		
		def stroke_width
			@stroke_width
		end
	end
end
